/**
  ******************************************************************************
  * @file    bsp_basic_tim.c
  * @author  STMicroelectronics
  * @version V1.0
  * @date    2015-xx-xx
  * @brief   鍩烘湰瀹氭椂鍣ㄥ畾鏃惰寖渚?
  ******************************************************************************
  * @attention
  *
  * 瀹為獙骞冲彴:閲庣伀 STM32F767 寮€鍙戞澘  
  * 璁哄潧    :http://www.firebbs.cn
  * 娣樺疂    :http://firestm32.taobao.com
  *
  ******************************************************************************
  */
  
#include "./tim/bsp_basic_tim.h"

TIM_HandleTypeDef TIM_TimeBaseStructure;
 /**
  * @brief  鍩烘湰瀹氭椂鍣? TIMx,x[6,7]涓?鏂?浼樺厛绾ч厤缃?
  * @param  鏃?
  * @retval 鏃?
  */
static void TIMx_NVIC_Configuration(void)
{
	//璁剧疆鎶㈠崰浼樺厛绾э紝瀛愪紭鍏堢骇
	HAL_NVIC_SetPriority(BASIC_TIM_IRQn, 0, 3);
	// 璁剧疆涓?鏂?鏉ユ簮
	HAL_NVIC_EnableIRQ(BASIC_TIM_IRQn);
}

/*
 * 娉ㄦ剰锛歍IM_TimeBaseInitTypeDef缁撴瀯浣撻噷闈㈡湁5涓?鎴愬憳锛孴IM6鍜孴IM7鐨勫瘎瀛樺櫒閲岄潰鍙?鏈?
 * TIM_Prescaler鍜孴IM_Period锛屾墍浠ヤ娇鐢═IM6鍜孴IM7鐨勬椂鍊欏彧闇€鍒濆?嬪寲杩欎袱涓?鎴愬憳鍗冲彲锛?
 * 鍙﹀?栦笁涓?鎴愬憳鏄?閫氱敤瀹氭椂鍣ㄥ拰楂樼骇瀹氭椂鍣ㄦ墠鏈?.
 *-----------------------------------------------------------------------------
 * TIM_Prescaler         閮芥湁
 * TIM_CounterMode			 TIMx,x[6,7]娌℃湁锛屽叾浠栭兘鏈夛紙鍩烘湰瀹氭椂鍣?锛?
 * TIM_Period            閮芥湁
 * TIM_ClockDivision     TIMx,x[6,7]娌℃湁锛屽叾浠栭兘鏈?(鍩烘湰瀹氭椂鍣?)
 * TIM_RepetitionCounter TIMx,x[1,8]鎵嶆湁(楂樼骇瀹氭椂鍣?)
 *-----------------------------------------------------------------------------
 */
static void TIM_Mode_Config(void)
{
	// 寮€鍚疶IMx_CLK,x[6,7] 
	BASIC_TIM_CLK_ENABLE(); 

	TIM_TimeBaseStructure.Instance = BASIC_TIM;
	/* 绱?璁? TIM_Period涓?鍚庝骇鐢熶竴涓?鏇存柊鎴栬€呬腑鏂?*/		
	//褰撳畾鏃跺櫒浠?0璁℃暟鍒?4999锛屽嵆涓?5000娆★紝涓轰竴涓?瀹氭椂鍛ㄦ湡
	TIM_TimeBaseStructure.Init.Period = 1000-1;       

	//瀹氭椂鍣ㄦ椂閽熸簮TIMxCLK = 2 * PCLK1  
	//				PCLK1 = HCLK / 4 
	//				=> TIMxCLK=HCLK/2=SystemCoreClock/2=108MHz
	// 璁惧畾瀹氭椂鍣ㄩ?戠巼涓?=TIMxCLK/(TIM_Prescaler+1)=10000Hz
	TIM_TimeBaseStructure.Init.Prescaler = 108-1;	

	// 鍒濆?嬪寲瀹氭椂鍣═IMx, x[2,3,4,5]
	HAL_TIM_Base_Init(&TIM_TimeBaseStructure);

	// 寮€鍚?瀹氭椂鍣ㄦ洿鏂颁腑鏂?
	HAL_TIM_Base_Start_IT(&TIM_TimeBaseStructure);	
}

/**
  * @brief  鍒濆?嬪寲鍩烘湰瀹氭椂鍣ㄥ畾鏃讹紝1ms浜х敓涓€娆′腑鏂?
  * @param  鏃?
  * @retval 鏃?
  */
void TIMx_Configuration(void)
{
	TIMx_NVIC_Configuration();	
  
	TIM_Mode_Config();
}

/*********************************************END OF FILE**********************/
